package com.mdp.workflow.bus.behavior;

import com.mdp.workflow.bus.candidate.TaskCandidateInvoker;
import lombok.Setter;
import org.flowable.bpmn.model.Activity;
import org.flowable.bpmn.model.UserTask;
import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior;
import org.flowable.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFactory;

/**
 * 自定义的 ActivityBehaviorFactory 实现类，目的如下：
 * 1. 自定义 {@link #createUserTaskActivityBehavior(UserTask)}：实现自定义的流程任务的 assignee 负责人的分配
 *
 *@author 唛盟开源9哥
 */
@Setter
public class ActivityBehaviorFactory extends DefaultActivityBehaviorFactory {

    private TaskCandidateInvoker taskCandidateInvoker;

    @Override
    public org.flowable.engine.impl.bpmn.behavior.UserTaskActivityBehavior createUserTaskActivityBehavior(UserTask userTask) {
        UserTaskActivityBehavior behavior= new UserTaskActivityBehavior(userTask);
        behavior.setTaskCandidateInvoker(taskCandidateInvoker);
        return behavior;
    }

    @Override
    public org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior createParallelMultiInstanceBehavior(Activity activity,
                                                                                                                    AbstractBpmnActivityBehavior behavior) {
        ParallelMultiInstanceBehavior behavior1 = new ParallelMultiInstanceBehavior(activity, behavior);
        behavior1.setTaskCandidateInvoker(taskCandidateInvoker);
        return behavior1;
    }

    @Override
    public org.flowable.engine.impl.bpmn.behavior.SequentialMultiInstanceBehavior createSequentialMultiInstanceBehavior(Activity activity,
                                                                                                                        AbstractBpmnActivityBehavior behavior) {
        SequentialMultiInstanceBehavior behavior1 =  new SequentialMultiInstanceBehavior(activity, behavior);
        behavior1.setTaskCandidateInvoker(taskCandidateInvoker);
        return behavior1;
    }

}
